#!/bin/bash

# 脚本说明
# 1. 启动zookeeper
# 2. 停止zookeeper
# 3. 重启zookeeper

# 启动zookeeper
function start_zookeeper() {
    echo "Starting zookeeper..."
    /usr/local/zookeeper/bin/zkServer.sh start
    echo "Zookeeper started successfully!"
}

# 停止zookeeper
function stop_zookeeper() {
    echo "Stopping zookeeper..."
    /usr/local/zookeeper/bin/zkServer.sh stop
    echo "Zookeeper stopped successfully!"
}

# 重启zookeeper
function restart_zookeeper() {
    echo "Restarting zookeeper..."
    /usr/local/zookeeper/bin/zkServer.sh restart
    echo "Zookeeper restarted successfully!"
}

# 脚本入口
if [ $# -eq 0 ]; then
    echo "Usage: $0 {start|stop|restart}"
    exit 1
fi

case "$1" in
    start)
        start_zookeeper
        ;;
    stop)
        stop_zookeeper
        ;;
    restart)
        restart_zookeeper
        ;;
    *)
        echo "Invalid argument: $1"
        exit 1
        ;;
esac